home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / ClutFade 1.3.2 / C / THINK C project (FadeTester) / Shell.c < prev    next >
C/C++ Source or Header  |  1996-04-23  |  5KB  |  207 lines

  1. /********************************************************************************
  2.  
  3.      PROJECT:    clut_fade.π
  4.      
  5.      FILE:        shell.c
  6.      
  7.      PURPOSE:    'clut' fading functions
  8.      
  9.      STATUS:        Public Domain Demo.
  10.  
  11.  ********************************************************************************/
  12.  
  13. //=================================    INCLUDES ====================================
  14.  
  15. #include "shell.h"
  16. #include "fade.h"
  17.  
  18. //=================================    FUNCTIONS ===================================
  19.  
  20. void init_toolbox(void);
  21. void test_window(void);
  22.  
  23.  
  24. /*********************************** main ***************************************/
  25. extern
  26. void main(void)
  27. {
  28.     init_toolbox();
  29.     test_window();    
  30. }
  31. /*** main ***/
  32.  
  33. /********************************** init_toolbox ********************************/
  34. static
  35. void init_toolbox(void)
  36. {
  37.     MaxApplZone();
  38.     MoreMasters();
  39.     InitGraf(&qd.thePort);
  40.     InitFonts();
  41.     InitWindows();
  42.     InitMenus();
  43.     TEInit();
  44.     InitDialogs(0);
  45.     InitCursor();
  46.     FlushEvents(everyEvent, 0);
  47. }
  48. /*** init_toolbox ***/
  49.  
  50. /********************************** test_window *********************************/
  51. static
  52. void test_window(void)
  53. {
  54.     DialogPtr    d;
  55.     GrafPtr        g;
  56.     short        hit;
  57.     GDHandle    hGD;
  58.     CTabHandle    hCTab;
  59.     long         ticks;
  60.     short         fadeSpeed;
  61.     Handle        iHandle;
  62.     short        iType;
  63.     Rect        iRect;
  64.     
  65.     if (d = GetNewDialog(128, nil, (WindowPtr) -1L))
  66.     {
  67.         GetPort(&g);
  68.         SetPort(d);
  69.         ShowWindow(d);
  70.         
  71.         do
  72.         {
  73.             ModalDialog(nil, &hit);
  74.             GetDItem(d,10,&iType,&iHandle,&iRect);
  75.             fadeSpeed = GetCtlValue((ControlHandle)iHandle);
  76.             switch (hit)
  77.             {
  78.                 // fade all monitors to black
  79.                 case    2:
  80.                     // fade out
  81.                     fade_to_black(fadeSpeed, fadeAll, true);
  82.                     // wait a few seconds
  83.                     Delay (120L, &ticks);
  84.                     // fade in
  85.                     fade_to_black(fadeSpeed, fadeAll, false);
  86.                     break;
  87.  
  88.                 // fade main monitor to black
  89.                 case    3:
  90.                     // fade out
  91.                     fade_to_black(fadeSpeed, fadeMainOnly, true);
  92.                     // wait a few seconds
  93.                     Delay (120L, &ticks);
  94.                     // fade in
  95.                     fade_to_black(fadeSpeed, fadeMainOnly, false);
  96.                     break;
  97.                     
  98.                 // fade all monitors except main monitor to black
  99.                 case    4:
  100.                     // fade out
  101.                     fade_to_black(fadeSpeed, fadeAllButMain, true);
  102.                     // wait a few seconds
  103.                     Delay (120L, &ticks);
  104.                     // fade in
  105.                     fade_to_black(fadeSpeed, fadeAllButMain, false);
  106.                     break;
  107.                     
  108.                 // fade main monitor to red
  109.                 case    5:
  110.                     {
  111.                     CTabHandle    origColors;
  112.                     GDHandle    mainDevice = GetMainDevice();
  113.                     RGBColor    aColor;
  114.                         
  115.                         // make a copy of the color table so we can restore it later
  116.                         copy_gdevice_clut(mainDevice,&origColors);
  117.                         
  118.                         // fade to a color
  119.                         aColor.red = 65535;
  120.                         aColor.green = 0;
  121.                         aColor.blue = 0;
  122.                         fade_to_color(fadeSpeed,&aColor,mainDevice);
  123.                         
  124.                         // wait a few seconds
  125.                         Delay (120L, &ticks);
  126.                         
  127.                         // fade back to original color table
  128.                         fade_to_clut(fadeSpeed,origColors,mainDevice);
  129.                         
  130.                         // dispose the copy we made
  131.                         DisposeHandle((Handle)origColors);
  132.                     }
  133.                     break;
  134.  
  135.                 // fade main monitor through rainbow
  136.                 case    6:
  137.                     {
  138.                     CTabHandle    origColors;
  139.                     CTabHandle    newColors;
  140.                     short        x;
  141.                     GDHandle    mainDevice = GetMainDevice();
  142.                         
  143.                         // make a copy of the color table so we can restore it later
  144.                         copy_gdevice_clut(mainDevice,&origColors);
  145.                         
  146.                         for (x = 128; x < 135; x++)
  147.                         {
  148.                             // get a custom color table (red or blue)
  149.                             newColors = GetCTable(x);
  150.                             // limit it to current depth
  151.                             (**newColors).ctSize = (**origColors).ctSize;
  152.                             SetHandleSize((Handle)(**newColors).ctTable, sizeof(short) + (sizeof(RGBColor) * ((**newColors).ctSize+1)));
  153.                             // fade to the custow color table
  154.                             fade_to_clut(40,newColors,mainDevice);
  155.                         ReleaseResource((Handle)newColors);
  156.                         }
  157.  
  158.                         // fade back to original color table
  159.                         fade_to_clut(40,origColors,mainDevice);
  160.                         // dispose the copy we made
  161.                         DisposeHandle((Handle)origColors);
  162.                     }
  163.                     break;
  164.                     
  165.                 // fade to inverted clut
  166.                 case    7:
  167.                     {
  168.                     CTabHandle    origColors;
  169.                     CTabHandle    newColors;
  170.                     RGBColor    aColor;
  171.                     short        x;
  172.                     GDHandle    mainDevice = GetMainDevice();
  173.                         
  174.                         // make a copy of the color table so we can restore it later
  175.                         copy_gdevice_clut(mainDevice,&origColors);
  176.                         // make a copy of the color table so we manipulate it
  177.                         copy_gdevice_clut(mainDevice,&newColors);
  178.                         // reverse order of colors for a fun effect
  179.                         for (x = 0; x < (((**newColors).ctSize+1)/2); x++)
  180.                         {
  181.                             aColor = (**newColors).ctTable[x].rgb;
  182.                             (**newColors).ctTable[x].rgb = (**newColors).ctTable[(**newColors).ctSize - x].rgb;
  183.                             (**newColors).ctTable[(**newColors).ctSize - x].rgb = aColor;
  184.                         }
  185.                         // change ctSeed so we know it is different
  186.                         (**newColors).ctSeed = GetCTSeed();
  187.                         // fade to it
  188.                         fade_to_clut(fadeSpeed,newColors,mainDevice);
  189.                         // wait a few seconds
  190.                         Delay (120L, &ticks);
  191.                         // fade back to original color table
  192.                         fade_to_clut(fadeSpeed,origColors,mainDevice);
  193.                         // dispose the copy we made
  194.                         DisposeHandle((Handle)origColors);
  195.                     }
  196.                     break;
  197.             }
  198.         }
  199.         while (hit != 1);
  200.         
  201.         SetPort(g);
  202.         DisposDialog(d);
  203.     }
  204. }
  205. /*** test_window ***/
  206.  
  207. //===================================== EOF =====================================